package com.plant.consult.service.impl;

import com.plant.consult.domain.BackgroundRecordVo;
import com.plant.consult.domain.Consult;
import com.plant.consult.domain.ConsultDetail;
import com.plant.consult.domain.ConsultRecord;
import com.plant.consult.mapper.ConsultMapper;
import com.plant.consult.mapper.ConsultRecordMapper;
import com.plant.consult.service.ConsultRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ConsultRecordServiceImpl implements ConsultRecordService {
    @Autowired
    ConsultRecordMapper consultRecordMapper;
    @Autowired
    ConsultMapper consultMapper;
    @Override
    public Integer insert(ConsultRecord consultRecord) {
        consultRecord.setStartTime(new Date());
        consultRecord.setEndTime(null);
        consultRecord.setStatus(0);
        consultRecord.setDel(0);
       consultRecordMapper.insert(consultRecord);
        consultMapper.updateStatus(consultRecord.getConId());
        return  consultRecordMapper.findById(consultRecord);
    }

    @Override
    public String findUserId(Integer phId) {
        List<ConsultRecord> userId = consultRecordMapper.findUserId(phId);
        if(userId.size()==2){
            return "接诊数量已满，请会诊完再接诊";
        }else if(userId.size()<2){
            return "可以接诊";
        }
       return null;
    }

    @Override
    public List<ConsultRecord> selectReply(Consult consult) {
        return consultRecordMapper.selectReply(consult);
    }

    @Override
    public List<BackgroundRecordVo> backgroundRecordSelect() {
        List<BackgroundRecordVo> backgroundRecordVos = consultRecordMapper.backgroundRecordSelect();
        for (BackgroundRecordVo backgroundRecordVo : backgroundRecordVos) {
            backgroundRecordVo.setAddress(backgroundRecordVo.getProvince()+"-"+backgroundRecordVo.getCity()+"-"+backgroundRecordVo.getDistrict());
        }
        return backgroundRecordVos;
    }

}
